package com.ruoyi.web.controller.system;

import java.io.IOException;
import java.util.List;

import com.ruoyi.common.core.text.Convert;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TBaseInformation;
import com.ruoyi.system.service.ITBaseInformationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;

/**
 * 考生基本信息Controller
 * 
 * @author ruoyi
 * @date 2024-12-20
 */
@Controller
@RequestMapping("/system/information")
public class TBaseInformationController extends BaseController
{
    private String prefix = "system/information";

    @Autowired
    private ITBaseInformationService tBaseInformationService;

    @RequiresPermissions("system:information:view")
    @GetMapping()
    public String information()
    {
        return prefix + "/information";
    }

    /**
     * 查询考生基本信息列表
     */
    @RequiresPermissions("system:information:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TBaseInformation tBaseInformation)
    {
        startPage();
        List<TBaseInformation> list = tBaseInformationService.selectTBaseInformationList(tBaseInformation);
        return getDataTable(list);
    }

    /**
     * 导出考生基本信息列表
     */
    @RequiresPermissions("system:information:export")
    @Log(title = "考生基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TBaseInformation tBaseInformation)
    {
        List<TBaseInformation> list = tBaseInformationService.selectTBaseInformationList(tBaseInformation);
        ExcelUtil<TBaseInformation> util = new ExcelUtil<TBaseInformation>(TBaseInformation.class);
        return util.exportExcel(list, "考生基本信息数据");
    }

    /**
     * 新增考生基本信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存考生基本信息
     */
    @RequiresPermissions("system:information:add")
    @Log(title = "考生基本信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TBaseInformation tBaseInformation)
    {
        return toAjax(tBaseInformationService.insertTBaseInformation(tBaseInformation));
    }

    /**
     * 修改考生基本信息
     */
    @RequiresPermissions("system:information:edit")
    @GetMapping("/edit/{baseId}")
    public String edit(@PathVariable("baseId") Long baseId, ModelMap mmap)
    {
        TBaseInformation tBaseInformation = tBaseInformationService.selectTBaseInformationByBaseId(baseId);
        mmap.put("tBaseInformation", tBaseInformation);
        return prefix + "/edit";
    }

    /**
     * 修改保存考生基本信息
     */
    @RequiresPermissions("system:information:edit")
    @Log(title = "考生基本信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TBaseInformation tBaseInformation)
    {
        return toAjax(tBaseInformationService.updateTBaseInformation(tBaseInformation));
    }

    /**
     * 删除考生基本信息
     */
    @RequiresPermissions("system:information:remove")
    @Log(title = "考生基本信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tBaseInformationService.deleteTBaseInformationByBaseIds(ids));
    }

    /**
     * 批量生成代码
     */
    @RequiresPermissions("system:information:add")
    @Log(title = "生成基本信息", businessType = BusinessType.GENCODE)
    @GetMapping("/batchGenBaseInfo")
    @ResponseBody
    public AjaxResult batchGenBaseInfo() throws IOException
    {
        return  AjaxResult.success(tBaseInformationService.batchGenBaseInfo());
    }
}
